package leetcode.D600.T518;

/**
 * @File Info: leetcode -- <Solution>
 * @Author: 18362
 * @Create: 2022-02-21 10:19:02 星期一
 */

class Solution {
    public int change(int amount, int[] coins) {
        int[] dp = new int[amount+1], temp = new int[amount+1];
        dp[0] = 1; temp[0] = 1;
        for(int i=0; i<coins.length; ++i) {
            for(int j=1; j<=amount; ++j) {
                int k = 1;
                while (k*coins[i] <= j) {
                    temp[j] += dp[j- k*coins[i]];
                    k++;
                }
            }
            System.arraycopy(temp, 0, dp, 0, temp.length);
        }
        return dp[amount];
    }
}